

s = tf('s');
testt = (2.1)/(0.1*s^2 + 0.2*s +1); %transfer function

stepsize=0.01;
tend=10; 
ts=(0:stepsize:tend)'; %sampling times
N=length(ts);

%       -1,-2,-3
ycoeff=[0.15;0.27;-0.43];
ucoeff=[0.73;3;7];

yl=length(ycoeff);
ul=length(ucoeff);

coeff=[ycoeff;ucoeff];


y=zeros(N,1);
y(1:yl)=[13;11;127];

omega=5; 
testinp=@(t) sin(omega*t.*t); %input function
u=testinp(ts); %inputs at times


for k=yl+1:N
    y(k)=coeff'*[y(k-1:-1:k-yl);u(k:-1:k-ul+1)];
end




%yl+1

firstentry=max(yl+1,ul);

ys=y(firstentry:N);


%[y(yl:N-1),y(yl-1:N-2),y(yl-2:N-3)...]

S = zeros(N-firstentry+1,length(coeff));



for k=1:yl
    S(:,k)=y(firstentry-k:N-k);
end

for k=0:(ul-1)
    S(:,k+1+yl)=u(firstentry-k:N-k);
end




%yp=lsim(testt,u,ts); %y_pure

disturbance=random('norm',0,ones(size(ys))*0.02);

%später noch durch transfer function jagen??

yd=ys+disturbance;

plot(ts(firstentry:N),[ys,yd])




phat=S\yd;


